Analysis to determine the most cost-effective and environmentally beneficial time of day to use energy, by comparing the relationship between electricity usage, weather, and electricity price in Ottawa, Toronto, and Niagara Falls.
Almost all the peak demand happen in winter and summer. Toronto uses significantly more electricity than other cities, and more volatile Overall, Toronto’s peak electricity demand has a certain downward trend over the years, Ottawa and Niagara are relatively stable. In contrast, Ottawa has the lowest electricity demand per capita, Niagara the highest, and Toronto is in the middle. Ottawa is the most efficient in terms of electricity demand
## `summarise()` has grouped output by 'month_year'. You can override using the
## `.groups` argument.
power output generation and demand are similar, with peaks occurring in summer and winter
If we look at demand and output together, we will find that they always show the same trend.
The only difference occurs in 2022. In this year, the demand in summer is higher than that in winter, but the output is the opposite.
demand_hour <- demand_data %>% select(-month_year,-date) %>%
pivot_longer(
-hour,
names_to = "city",
values_to = "volumn"
)
demand_hour <- aggregate(demand_hour$volumn, by=list(demand_hour$hour,demand_hour$city),mean) %>%
rename(Hour=Group.1,city=Group.2,demand = x) %>%
mutate(hours=as.character(Hour))
mean <- demand_hour%>% group_by(city)%>%summarise(mean_val=quantile(demand,0.6))
demand_hour %>%
ggplot(aes( x = reorder(hours,Hour),y = demand, colour = city,group=city))+
geom_line(aes(color=city)) +
geom_point(size=2) +
geom_hline(data=mean,aes(yintercept=mean_val,color=city,linetype="60 percentiles of the demand(base load)"))+ #cite 1
theme_minimal() +
labs(
x = 'Period (hour)',
y = 'Power demand(MW)',
colour = 'city'
)
lowest demand happen on 4am and start increase untill reach the peak which is 6pm. After 6pm, the demand decrease. When we look at demand from the perspective of hours, based on the base load(60%), from 10 am to 9 pm, the demand exceeds the base load. So if you want to be more environmental friendly, use the electricity before 10am or after 9pm.
## `summarise()` has grouped output by 'delivery_date', 'month_year'. You can
## override using the `.groups` argument.
## Adding missing grouping variables: `delivery_date`, `month_year`
Power output is pretty much the same as demand. lowest output happen on 3am and highest happen on 6pm.
## `summarise()` has grouped output by 'hours'. You can override using the
## `.groups` argument.
If we look at demand and output together, they are almost showing the same trend.
df2 %>% select(Time,Hour,demand,capacity) %>%
ggplot(aes(x=demand,y=capacity,size=demand/capacity,color=Hour),alpha=0.8) +
geom_point() +
stat_smooth(method = glm,level=0.95) +
scale_size_continuous(range = c(2, 10)) +
geom_label_repel(aes(label = Hour),size=3)
method = glm,level=0.95 we need to prevent using electricity on the hour above the line, which is 6pm to 9pm since for the same demand it need higher capacity which may increase power plant emissions. Switch them to the hour below the line may be a good idea.
getPrice <- function(filename){
temp <- read_csv(filename,skip = 3, col_names = TRUE,show_col_types = FALSE) %>%
clean_names() %>%
select(date,hour,hoep)
return(temp)
}
price_data <- tibble()
for (i in 2019:2023)
{
filename = paste("PUB_PriceHOEPPredispOR_",i,".csv",sep = "")
price_data <- price_data %>% bind_rows(getPrice(filename)) %>%
mutate(month_year = format(as.Date(date), "%Y-%m"))
}
price_month <- price_data %>%
select(month_year,hoep) %>%
group_by(month_year) %>%
summarise(price = mean(hoep))
price_month %>%
ggplot(aes( x = month_year, y = price))+
geom_line(aes(size=2),group=1,color="darkgreen") +
theme_minimal() +
labs(
x = 'Period (year)',
y = 'price($ CAD per MWh)'
) +
theme(axis.text.x = element_text(angle=90,hjust=0.5, vjust=0.5))
There is a very, very significant increase in electricity prices from summer 2022. The possible reason is that the war in Ukraine has caused global energy problems
price_hour <- price_data %>%
select(hour,hoep) %>%
group_by(hour) %>%
summarise(price_val=mean(hoep)) %>%
mutate(hours=as.character(hour))
price_hour %>%
ggplot(aes( x = reorder(hours,hour), y = price_val))+
geom_line(aes(size=2),group=1,color="darkgreen") +
theme_minimal() +
labs(
x = 'Period (hour)',
y = 'price($ CAD per MWh)'
) +
theme(axis.text.x = element_text(angle=90,hjust=0.5, vjust=0.5))
If we look at the price from an hourly perspective,Two peaks occur at
10 am and 6:00 pm The difference from the demand is that the price shows
a decline from 10am in the morning to 2pm in the afternoon. If you want
to be more economical, you can try to use electricity between 10pm and
7am,Especially between 1am and 5am,During this time period, the
electricity bill is basically equal to 0.
df3 <- demand_hour2 %>%
left_join(price_hour,by=c("hours"="hours")) %>%
select(-hour)
df3 %>%
ggplot(aes(x=mean_val,y=price_val,size=price_val,color=Hour),alpha=0.8) +
geom_point() +
stat_smooth(method = glm,level=0.99) +
scale_size_continuous(range = c(2, 10))+
labs(
x = 'Demand (MW)',
y = 'price($ CAD per MWh)'
) +
geom_label_repel(aes(label = hours, fontface = "bold"),size=3)
method:glm, level:0.99
1am to 6am is the most economical It is relatively economical to use electricity between 1pm and 4pm. And 8am to 10am is relatively the least economical
temp_hour <- tibble()
cities <- c("6139449","6105978","6158355")
months <- c("01","02","03","04","05","06","07","08","09","10","11","12")
for(i in cities)
{
for (j in 2019:2023)
{
for(k in months)
{
filename = paste("en_climate_hourly_ON_",i,"_",k,"-",j,"_P1H.csv",sep = "")
if (file.exists(filename))
{
temp <-read_csv(filename,col_names = TRUE,show_col_types = FALSE) %>%
clean_names()%>%select(station_name,temp_c,date_time_lst,day,time_lst) %>%
mutate(hour=as.numeric(gsub(".?([0-9]+).", "\\1",date_time_lst)))%>%select(-time_lst)%>%mutate(month_year = format(as.Date(date_time_lst), "%Y-%m"))
temp_hour <- temp_hour %>% bind_rows(temp)
}
}
}
}
temp_hour <-temp_hour%>%pivot_wider(names_from = station_name, values_from = temp_c)%>%clean_names()%>%setnames(old = c('welland_pelham','ottawa_cda_rcs','toronto_city'),new = c('Niagara','Ottawa','Toronto'))
temp_month <- temp_hour %>%
select (month_year,Niagara,Ottawa,Toronto) %>%
pivot_longer(-month_year,
names_to = "city",
values_to = "temp") %>%
drop_na() %>%
group_by(month_year,city) %>%
summarise(mean_temp=mean(temp))
temp_month %>%
ggplot(aes( x = month_year, y = mean_temp,group=city,color=city))+
geom_line(aes(color=city)) +
geom_point()+
geom_smooth(method='loess',aes(group=city))+
theme_minimal() +
labs(
x = 'Period (year)',
y = 'Average Temperature(ËšC)'
) +
theme(axis.text.x = element_text(angle=90,hjust=0.5, vjust=0.5))
Toronto is the warmest and Ottawa is the coldest.
Temperature is similar in summer for those three cities. But for winter, Ottawa is much more colder, maybe it’s due to great lake effect.
global warming is not trun for Ontario.
temp_data <- tibble()
temp_hour<- tibble()
cities <- c("6139449","6105978","6158355")
months <- c("01","02","03","04","05","06","07","08","09","10","11","12")
for(i in cities)
{
for (j in 2019:2023)
{
for(k in months)
{
filename = paste("en_climate_hourly_ON_",i,"_",k,"-",j,"_P1H.csv",sep = "")
if (file.exists(filename))
{
temp <-read_csv(filename,col_names = TRUE,show_col_types = FALSE) %>%
clean_names()%>%select(station_name,temp_c,date_time_lst,day,time_lst) %>%
mutate(hour=as.numeric(gsub(".*?([0-9]+).*", "\\1",time_lst)))%>%select(-time_lst)%>%mutate(month_year = format(as.Date(date_time_lst), "%Y-%m"))
temp_data <- temp_data %>% bind_rows(temp)
}
}
}
}
temp_data<-temp_data%>%pivot_wider(names_from = station_name, values_from = temp_c)%>%clean_names()%>%setnames(old = c('welland_pelham','ottawa_cda_rcs','toronto_city'),new = c('niagara','ottawa','toronto'))
temp_hour <- temp_data %>%select (hour,niagara,ottawa,toronto) %>% pivot_longer(-hour,names_to = "city",values_to = "temp") %>%drop_na() %>% group_by(hour,city) %>%summarise(mean_temp_hour=mean(temp))#%>%pivot_wider(names_from = city, values_from = mean_temp)
ggplot(temp_hour, mapping = aes(x = hour, y = mean_temp_hour, color = city) ) + geom_line()+
geom_point()+
labs(
x = 'Period (Hours)',
y = 'Temperature(ËšC)')
Toronto and Niagara are similar, Ottawa still the coldest. lowest temperature always happen on 5am and highest is around 2-3pm.
temp_hour2 <- temp_data %>%pivot_longer(cols = c('niagara', 'ottawa', 'toronto'), names_to = 'city', values_to = 'temp') %>% select(month_year, city, temp)%>% drop_na()%>% group_by(city, month_year) %>% summarise(mean_temp = mean(temp))
demand_temp <- left_join(demand_month,temp_hour2,by = c("city"="city","Time"="month_year"))
demand_temp %>%
ggplot(aes( x = mean_temp,y = demand, colour = city,group=city))+
geom_line(aes(color=city)) +
geom_point(size=2) +
geom_smooth(method = "glm")+
theme_minimal() +
labs(
x = 'Temp (C)',
y = 'Power demand(MW)',
colour = 'city' )
Looks like Toronto has a positive correlation between temperature and
demand.
Ottawa has a negative correlation between temperature and demand.
Niagara is neutral.
If you want to be more environmental friendly, use electricity before 10am or after 9pm.
If you have to, 12pm-2pm is the best choice.
If you want to save money, try to go between 1am and 6am
If you have to, 1pm-4pm is the best choice
Global Adjustment
regression on price,demand,weather
some extreme weather conditions
benford analysis
sessionInfo()
## R version 4.2.2 (2022-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.3
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggtrendline_1.0.3 data.table_1.14.8 benford.analysis_0.1.5
## [4] tictoc_1.1 patchwork_1.1.2 scales_1.2.1
## [7] ggrepel_0.9.2 janitor_2.1.0 readxl_1.4.1
## [10] lubridate_1.9.0 timechange_0.2.0 knitr_1.41
## [13] forcats_1.0.0 stringr_1.5.0 dplyr_1.0.10
## [16] purrr_1.0.1 readr_2.1.3 tidyr_1.2.1
## [19] tibble_3.1.8 ggplot2_3.4.0 tidyverse_1.3.2
## [22] flexdashboard_0.6.1
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.4 sass_0.4.4 splines_4.2.2
## [4] bit64_4.0.5 vroom_1.6.0 jsonlite_1.8.4
## [7] modelr_0.1.10 bslib_0.4.2 assertthat_0.2.1
## [10] highr_0.10 googlesheets4_1.0.1 cellranger_1.1.0
## [13] yaml_2.3.6 lattice_0.20-45 pillar_1.8.1
## [16] backports_1.4.1 glue_1.6.2 digest_0.6.31
## [19] rvest_1.0.3 snakecase_0.11.0 colorspace_2.0-3
## [22] Matrix_1.5-1 htmltools_0.5.4 pkgconfig_2.0.3
## [25] broom_1.0.2 haven_2.5.1 tzdb_0.3.0
## [28] googledrive_2.0.0 mgcv_1.8-41 farver_2.1.1
## [31] generics_0.1.3 ellipsis_0.3.2 cachem_1.0.6
## [34] withr_2.5.0 cli_3.6.0 magrittr_2.0.3
## [37] crayon_1.5.2 evaluate_0.19 fs_1.5.2
## [40] fansi_1.0.3 nlme_3.1-160 xml2_1.3.3
## [43] tools_4.2.2 hms_1.1.2 gargle_1.3.0
## [46] lifecycle_1.0.3 munsell_0.5.0 reprex_2.0.2
## [49] compiler_4.2.2 jquerylib_0.1.4 rlang_1.0.6
## [52] grid_4.2.2 rstudioapi_0.14 labeling_0.4.2
## [55] rmarkdown_2.19 gtable_0.3.1 DBI_1.1.3
## [58] R6_2.5.1 fastmap_1.1.0 bit_4.0.5
## [61] utf8_1.2.2 stringi_1.7.12 parallel_4.2.2
## [64] Rcpp_1.0.9 vctrs_0.5.1 dbplyr_2.3.0
## [67] tidyselect_1.2.0 xfun_0.36